package cn.biplam.front.template.buttons;

import cn.biplam.common.wrapper.ErrorMessage;
import cn.biplam.common.wrapper.UserInfo;
import cn.biplam.front.component.data.common.ButtonComp;
import cn.biplam.front.html.base.HtmlWindow;
import cn.biplam.front.html.base.Const.Window_Event;
import cn.biplam.front.htmlscript.script.AjxScript;
import cn.biplam.front.template.Template;

/**
 * 刷新按钮模板<BR>
 * 如果不传rID,需确保刷新的action处理不需要rID
 * @author 	WangSong 2009-10-21 上午09:00:58
 * @version 1.0
 */
public class RefreshButton implements Template{
	
	private UserInfo mUser;
	private String cID;
	private String aID;
	private String rID;

	/**
	 * 不需要rid的刷新
	 * @param mUser		用户信息类
	 * @param cID		需要刷新的容器ID
	 * @param aID		刷新的actionID
	 */
	public RefreshButton(UserInfo mUser,String cID,String aID){
		this(mUser, cID, aID,null);
	}
	
	/**
	 * 需要rid的刷新
	 * @param mUser		用户信息类
	 * @param cID		需要刷新的容器ID
	 * @param aID		刷新的actionID
	 * @param rID		刷新提交的recordID
	 */
	public RefreshButton(UserInfo mUser,String cID,String aID,String rID){
		this.mUser=mUser;
		this.cID=cID;
		this.aID=aID;
		this.rID=rID;
	}

	/**
	 * 返回按钮页面组件
	 * @return	HtmlWindow
	 * @throws ErrorMessage
	 */
	public HtmlWindow get() throws ErrorMessage {
		HtmlWindow refreshBt=ButtonComp.get(mUser, "200");
		refreshBt.bind(Window_Event.OnClick, this.getScript());
		return refreshBt;
	}
	
	/**
	 * 返回按钮点击时执行的脚本
	 * @return String
	 */
	public String getScript(){
		if(this.rID==null){
			return AjxScript.getA(cID,aID);
		}
		return AjxScript.getA(cID,aID,rID);
	}
}
